package com.zbs.framework.dao.passport.base.service.impl;

import com.zbs.framework.common.utils.Constant;
import com.zbs.framework.common.utils.ErrorAssert;
import com.zbs.framework.dao.passport.base.repository.MNAccountRepository;
import com.zbs.framework.dao.passport.base.service.AccountService;
import com.zbs.framework.dao.passport.entity.MNAccount;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class AccountServiceImpl implements AccountService {

    @Autowired
    private MNAccountRepository accountRepository;

    @Override
    public MNAccount setEnabled(String uuid, Integer enabled) {
        // 参数检查
        ErrorAssert.hasLength(uuid, "UUID can not be empty!");
        ErrorAssert.notNull(enabled, "Enabled can not be null!");
        // 查找账号
        MNAccount account = accountRepository.findById(uuid).orElse(null);
        ErrorAssert.notNull(account, "Account not found!");
        // 修改状态
        account.setEnabled(Constant.YES.equals(enabled) ? Constant.YES : Constant.NO);
        accountRepository.save(account);
        return account;
    }
}
